package nosql.property;

/**
 * Property includes four features: 
 * 		entityId: 	indicate which entity it belongs to.
 * 		propertyId:	used to identify the property.
 * 		type:		include integer, double, boolean, string, complex, 
 * 					array_integer, array_double, array_string, array_complex. 
 * 					integer type indicate the property contains Integer,
 * 					double type indicate the property contains Double,
 * 					boolean type indicate the property contains Boolean,
 * 					string type indicates the property contains String,
 * 					complex type indicates the property contains other property.
 * 					array type indicates the property is an array,
 * 					
 * 		value:		the value of property, if property is in type array or complex,
 * 					value store the propertyId of the sub-element(s), 
 * 					otherwise it stores the actually value.
 * @author Yexi Jiang <http://sites.google.com/site/yexijiang/>
 *
 */
public class Property {
	
	public static final int UNDEFINED = -1;
	public static final int INTEGER = 0;
	public static final int DOUBLE = 1;
	public static final int FLOAT = 2;
	public static final int BOOLEAN = 3;
	public static final int STRING = 4;
	public static final int LONG = 5;
	public static final int SHORT = 6;
	public static final int COMPLEX = 7;
	
	public static final int ARRAY = 8;
	public static final int ARRAY_INTEGER = 9;
	public static final int ARRAY_DOUBLE = 10;
	public static final int ARRAY_FLOAT = 11;
	public static final int ARRAY_BOOLEAN = 12;
	public static final int ARRAY_LONG = 13;
	public static final int ARRAY_SHORT = 14;
	public static final int ARRAY_STRING = 15;
	public static final int ARRAY_COMPLEX = 16;
	
	public static final int NUMBER = 17;
	
	private String tableName;
	private String entityId;
	private int propertyId;
	private int type;
	private String ref;
	
	public Property(String tableName, String entityId, int propertyId, int type, String ref){
		this.setTableName(tableName);
		this.setEntityId(entityId);
		this.setPropertyId(propertyId);
		this.setType(type);
		this.setRef(ref);
	}
	
	public String getTableName() {
		return tableName;
	}

	public void setTableName(String tableName) {
		this.tableName = tableName;
	}

	public String getEntityId() {
		return entityId;
	}
	
	public void setEntityId(String entityId) {
		this.entityId = entityId;
	}
	
	public int getPropertyId() {
		return propertyId;
	}
	
	public void setPropertyId(int propertyId) {
		this.propertyId = propertyId;
	}

	public int getType() {
		return type;
	}

	public void setType(int type) {
		if(type >= 0 && type <=16)
			this.type = type;
	}

	public String getRef() {
		return ref;
	}

	public void setRef(String ref) {
		this.ref = ref;
	}
	
	public String toString(){
		return tableName + "\t" + entityId + "\t" + propertyId + "\t" + parseType(type) + "\t" + ref;
	}
	
	private String parseType(int type){
		switch (type) {
		case 0:
			return "Integer";
		case 1:
			return "Double";
		case 2:
			return "Float";
		case 3:
			return "Boolean";
		case 4:
			return "String";
		case 5:
			return "Long";
		case 6:
			return "Short";
		case 7:
			return "Complex";
		case 8:
			return "Array";
		case 9:
			return "Array_Integer";
		case 10:
			return "Array_Double";
		case 11:
			return "Array_Float";
		case 12:
			return "Array_Boolean";
		case 13:
			return "Array_Long";
		case 14:
			return "Array_Short";
		case 15:
			return "Array_String";
		case 16:
			return "Array_Complex";
		default:
			return "Error";
		}
	}

}
